<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="container" contenteditable="true">

  </div>
</body>
<script>
  const container = document.getElementById('container')

  container.addEventListener('beforeinput', (e) => {

    const get = window.getSelection()
    console.log(get.anchorNode.childNodes[0], '11111111111111111111111111111')
    // get.anchorNode.childNodes[0].set
    get.setPosition(get.anchorNode.childNodes[0], 1)
    e.preventDefault()
  })
  // container.addEventListener('keydown', (e) => {
  //   // console.log(e, '123123')
  //   if (e.key === 'Delete') {
  //     console.log('删除')
  //   }
  // })
</script>

</html>